package com.unit.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unit.test.dao.UserMapper;
import com.unit.test.model.User;
import com.unit.test.service.UserService;
import org.apache.ibatis.builder.ParameterExpression;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.security.InvalidParameterException;
import java.util.List;


/**
 * @author lht
 * @version 1.0
 * @date 2024/2/19 21:36
 * @description
 */
@Service()
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User findByName(String name) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getName, name);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public List<User> findByIdList(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            throw new InvalidParameterException("参数错误");
        }
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(User::getId, idList);
        return list(lambdaQueryWrapper);
    }
}
